package top.chmin.project.cloud.sys.code;
import java.util.stream.Stream;
import java.util.List;
import java.util.ArrayList;

import top.chmin.project.cloud.common.*;
import lombok.experimental.Accessors;
import lombok.Setter;
import lombok.Getter;



/**
 * chmin
 * 2024-01-26 14:00:51
 * cloud-code
 */
public class CodeCondition extends Condition {
    private CodeCondition parent = null;

    CodeCondition() {
    }

    private CodeCondition(CodeCondition condition) {
        this.parent = condition;
    }

    public static CodeCondition forDelete() {
        CodeCondition condition = new CodeCondition();
        condition.setSql("DELETE FROM sys_code#where##group##order##limit#");
        return condition;
    }

    public static CodeCondition forSelect() {
        CodeCondition condition = new CodeCondition();
        condition.modelClass = Code.class;
        condition.setSql("SELECT #select# FROM sys_code#where##group##order##limit#");
        return condition;
    }

    public CodeCondition distinct() {
        this.distinct = true;
        return this;
    }

    public CodeCondition limit(int limit) {
        this.limit = " LIMIT " + limit;
        return this;
    }

    public CodeCondition sub() {
        return new CodeCondition(this);
    }

    public CodeCondition finish() {
        if (!whereList.isEmpty()) {
            parent.whereList.add("(" + String.join(" OR ", whereList) + ")");
        }
        parent.whereValueList.addAll(whereValueList);
        return parent;
    }

    public Code selectFirst() {
        return selectFirst(Code.class);
    }

    public List<Code> selectList() {
        return selectList(Code.class);
    }

    public Stream<Code> selectStream() {
        return selectStream(Code.class);
    }

    public Page<Code> selectPage() {
        return selectPage(Code.class);
    }

    /*###########auto#start###########*/
    public static int deleteByColumnCodeAndDate(String columnCode, String date) {
        return forDelete().columnCode().eq(columnCode).date().eq(date).execute();
    }

    public static Code selectByColumnCodeAndDate(String columnCode, String date) {
        return forSelect().columnCode().eq(columnCode).date().eq(date).selectFirst(Code.class);
    }

    public static <T> T selectByColumnCodeAndDate(String columnCode, String date, Class<T> clazz) {
        return forSelect().columnCode().eq(columnCode).date().eq(date).selectFirst(clazz);
    }

    /*###########auto##end############*/
    /* append $conditionIndexAppender$ */
    /*###########auto#start###########*/
    public ColumnCode columnCode() {
        return new ColumnCode();
    }

    public class ColumnCode extends StringFlexColumn<CodeCondition> {
        private ColumnCode() {
            super(CodeCondition.this, "column_code");
        }
    }

    public CreateBy createBy() {
        return new CreateBy();
    }

    public class CreateBy extends StringFlexColumn<CodeCondition> {
        private CreateBy() {
            super(CodeCondition.this, "create_by");
        }
    }

    public CreateTime createTime() {
        return new CreateTime();
    }

    public class CreateTime extends LocalDateTimeFlexColumn<CodeCondition> {
        private CreateTime() {
            super(CodeCondition.this, "create_time");
        }
    }

    public Date date() {
        return new Date();
    }

    public class Date extends StringFlexColumn<CodeCondition> {
        private Date() {
            super(CodeCondition.this, "date");
        }
    }

    public FixLength fixLength() {
        return new FixLength();
    }

    public class FixLength extends IntegerFlexColumn<CodeCondition> {
        private FixLength() {
            super(CodeCondition.this, "fix_length");
        }
    }

    public Id id() {
        return new Id();
    }

    public class Id extends IntegerFlexColumn<CodeCondition> {
        private Id() {
            super(CodeCondition.this, "id");
        }
    }

    public NextValue nextValue() {
        return new NextValue();
    }

    public class NextValue extends IntegerFlexColumn<CodeCondition> {
        private NextValue() {
            super(CodeCondition.this, "next_value");
        }
    }

    public Prefix prefix() {
        return new Prefix();
    }

    public class Prefix extends StringFlexColumn<CodeCondition> {
        private Prefix() {
            super(CodeCondition.this, "prefix");
        }
    }

    public UpdateBy updateBy() {
        return new UpdateBy();
    }

    public class UpdateBy extends StringFlexColumn<CodeCondition> {
        private UpdateBy() {
            super(CodeCondition.this, "update_by");
        }
    }

    public UpdateTime updateTime() {
        return new UpdateTime();
    }

    public class UpdateTime extends LocalDateTimeFlexColumn<CodeCondition> {
        private UpdateTime() {
            super(CodeCondition.this, "update_time");
        }
    }

    /*###########auto##end############*/
    /* append $conditionFieldAppender$ */
}
